package com.ruoyi.ylyx.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ylyx.domain.YlyxGameaccount;
import com.ruoyi.ylyx.service.IYlyxGameaccountService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户游戏账户Controller
 * 
 * @author yuexl
 * @date 2021-02-05
 */
@Controller
@RequestMapping("/ylyx/gameaccount")
public class YlyxGameaccountController extends BaseController
{
    private String prefix = "ylyx/gameaccount";

    @Autowired
    private IYlyxGameaccountService ylyxGameaccountService;

    @RequiresPermissions("ylyx:gameaccount:view")
    @GetMapping()
    public String gameaccount()
    {
        return prefix + "/gameaccount";
    }

    /**
     * 查询用户游戏账户列表
     */
    @RequiresPermissions("ylyx:gameaccount:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YlyxGameaccount ylyxGameaccount)
    {
        startPage();
        List<YlyxGameaccount> list = ylyxGameaccountService.selectYlyxGameaccountList(ylyxGameaccount);
        return getDataTable(list);
    }

    /**
     * 导出用户游戏账户列表
     */
    @RequiresPermissions("ylyx:gameaccount:export")
    @Log(title = "用户游戏账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YlyxGameaccount ylyxGameaccount)
    {
        List<YlyxGameaccount> list = ylyxGameaccountService.selectYlyxGameaccountList(ylyxGameaccount);
        ExcelUtil<YlyxGameaccount> util = new ExcelUtil<YlyxGameaccount>(YlyxGameaccount.class);
        return util.exportExcel(list, "gameaccount");
    }

    /**
     * 新增用户游戏账户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户游戏账户
     */
    @RequiresPermissions("ylyx:gameaccount:add")
    @Log(title = "用户游戏账户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YlyxGameaccount ylyxGameaccount)
    {
        return toAjax(ylyxGameaccountService.insertYlyxGameaccount(ylyxGameaccount));
    }

    /**
     * 修改用户游戏账户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        YlyxGameaccount ylyxGameaccount = ylyxGameaccountService.selectYlyxGameaccountById(id);
        mmap.put("ylyxGameaccount", ylyxGameaccount);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户游戏账户
     */
    @RequiresPermissions("ylyx:gameaccount:edit")
    @Log(title = "用户游戏账户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YlyxGameaccount ylyxGameaccount)
    {
        return toAjax(ylyxGameaccountService.updateYlyxGameaccount(ylyxGameaccount));
    }

    /**
     * 删除用户游戏账户
     */
    @RequiresPermissions("ylyx:gameaccount:remove")
    @Log(title = "用户游戏账户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ylyxGameaccountService.deleteYlyxGameaccountByIds(ids));
    }
}
